home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Disc to the Future 2
/
Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin
/
MAC
/
MACSHELL
/
MS1
/
COMMANDS
/
LISTCMDS.C
< prev
next >
Wrap
Text File
|
1992-12-02
|
13KB
|
517 lines
/*
* MacShell Source File
*
* Copyright (c) 1989, 1990, 1991, 1992 Suick Bay Technologies. All rights reserved.
*
*
* RESTRICTIONS ON MacShell program and source code.
*
* Ñ╩MacShell¬ is a product of Suick Bay Technologies and is provided for
* restricted use by the owner of the CDROM "Disk to the future II".
*
* Ñ╩No permission is granted for any commercial use without the written
* consent of the Suick Bay Technologies.
*
* Ñ╩No permission is granted for any redistribution of any kind use without
* the written consent of the Suick Bay Technologies.
*
* Ñ╩Permission is granted to use this for any personal noncommercial use.
*
* Ñ╩You may not distribute source or executable code at all, nor may you
* distribute it with or within a commercial product without the written
* consent of the Suick Bay Technologies. Please send modifications to
* the author for inclusion in updates to the program. Thanks.
*
*
* MacShell¬ IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
* WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
* PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
*
* SUICK BAY TECHNOLOGIES SHALL HAVE NO LIABILITY WITH RESPECT TO THE
* INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY MACSHELL
* OR ANY PART THEREOF.
*
* In no event will Suick Bay Technologies be liable for any lost revenue
* or profits or other special, indirect and consequential damages, even if
* Suick Bay Technologies has been advised of the possibility of such damages.
*
* Suick Bay Technologies can be reached at:
*
* 8768 Cottonwood lane
* Maple Grove, MN 55369
* Voice: (612) 425-7025
* AppleLink: D5233
*
*
* No parts of this software may be reproduced or stored in a
* retrieval system or transmitted in any form, or any means,
* electronic, mechanical, photocopying, recording or otherwise,
* without the prior written permission of Suick Bay Technologies.
*
* Spread the word and not the disk.
*
* SPK 040160 : reversed -m and -l options
* SPK 030190 : Update for Mac, DOS paths
* SPK 012290 : Initial
*/
#include "SystemPub.h"
#include "Proc.h"
#include "ShellPub.h"
#include "Path.h"
#include "Prefs.h"
#define lslmode (**MyShell).Proc[ProcID].bflags.f0
#define lsdmode (**MyShell).Proc[ProcID].bflags.f1
#define lscmode (**MyShell).Proc[ProcID].bflags.f2
#define lstmode (**MyShell).Proc[ProcID].bflags.f3
#define dirSpec (**MyShell).Proc[ProcID].bflags.f4
#define lsHead (**MyShell).Proc[ProcID].bflags.f5
#define lsamode (**MyShell).Proc[ProcID].bflags.f6
#define lsmmode (**MyShell).Proc[ProcID].bflags.f6
/*******************************************************************/
#define fLocked 1
#define fSystem 0x1000
#define fInited 0x0100
#define fShared 0x0040
#define fSwtLan 0x0020
#define fNoInit 0x0080
#define fBusy 0x0400
#define fChange 0x0200
GetFileAttrString( HFileInfo *pb, char *str )
{
int16 forceAttr,
attrLocked,
attrInvis,
attrBundle,
attrSystem,
attrInited,
attrDeskTop,
attrShared,
attrSwitch;
attrLocked = (pb->ioFlAttrib & fLocked);
attrInvis = (pb->ioFlFndrInfo.fdFlags & fInvisible);
attrBundle = (pb->ioFlFndrInfo.fdFlags & fHasBundle);
attrSystem = (pb->ioFlFndrInfo.fdFlags & fSystem);
attrInited = (pb->ioFlFndrInfo.fdFlags & fInited);
attrDeskTop = (pb->ioFlFndrInfo.fdFlags & fOnDesk);
attrShared = (pb->ioFlFndrInfo.fdFlags & fShared);
attrSwitch = (pb->ioFlFndrInfo.fdFlags & fSwtLan);
str[ 0 ] = ( attrLocked ? 'L' : 'l' );
str[ 1 ] = ( attrInvis ? 'V' : 'v' );
str[ 2 ] = ( attrBundle ? 'B' : 'b' );
str[ 3 ] = ( attrSystem ? 'S' : 's' );
str[ 4 ] = ( attrInited ? 'I' : 'i' );
str[ 5 ] = ( attrDeskTop? 'D' : 'd' );
str[ 6 ] = ( attrShared ? 'M' : 'm' );
str[ 7 ] = ( attrSwitch ? 'A' : 'a' );
str[ 8 ] = '\0';
}
/*******************************************************************/
void LsHeader( WHandle ShellWh, int16 ProcID )
{
ShellWindRec **MyShell = (ShellWindRec **) (**ShellWh).thing;
if( lslmode && lsHead )
{
lsHead = FALSE;
procPrintf( ShellWh, ProcID,
"Name Type Crtr Size Flags Last-Mod-Date Creation-Date\n" );
procPrintf( ShellWh, ProcID,
"-------------------- ---- ---- ------ -------- ----------------- -----------------\n" );
}
else if( lsmmode && lsHead )
{
lsHead = FALSE;
procPrintf( ShellWh, ProcID,
" Flags Type Crtr Size Name\n" );
procPrintf( ShellWh, ProcID,
"-------- ---- ---- ------ --------------------\n" );
}
}
/*******************************************************************/
void ListCallBack( WHandle ShellWh, int16 ProcID, char *path, char *last,
pathType what, int16 vRefNum, int32 dirID )
{
char str[ 256 ], dirChar;
char modified[ 64 ], created[ 64 ];
OSErr err;
DateTimeRec modDate, creDate;
int32 fLen;
char type[ 16 ], crea[ 16 ], flags[ 16 ], *dir, scale = ' ';
CInfoPBRec pb;
ShellWindRec **MyShell = (ShellWindRec **) (**ShellWh).thing;
LsHeader( ShellWh, ProcID );
strcpy( str, last );
CtoPstr( str );
dirChar = DirSep();
if( what == pathIsDir )
{
pb.dirInfo.ioCompletion = NULL;
pb.dirInfo.ioNamePtr = NULL;
pb.dirInfo.ioVRefNum = vRefNum;
pb.dirInfo.ioDrDirID = dirID;
pb.dirInfo.ioFDirIndex = -1;
err = PBGetCatInfo( &pb, FALSE );
fLen = 0L;
if( lslmode || lsmmode )
GetDirSize( str, vRefNum, dirID, &fLen );
Secs2Date( pb.dirInfo.ioDrCrDat, &creDate );
Secs2Date( pb.dirInfo.ioDrMdDat, &modDate );
GetFileAttrString( (HFileInfo *) &pb, flags );
strcpy( type, "Fldr" );
strcpy( crea, "Fldr" );
}
else if( what == pathIsVol )
{
unsigned int32 blksize, total;
HVolumeParam vpb;
fLen = 0L;
vpb.ioCompletion = 0L;
vpb.ioNamePtr = (StringPtr) str;
vpb.ioVRefNum = vRefNum;
vpb.ioVolIndex = (-1);
err = PBHGetVInfo( &vpb, FALSE );
blksize = (unsigned int32) vpb.ioVAlBlkSiz;
total = (unsigned int32) vpb.ioVNmAlBlks & 0x0000FFFF;
total *= blksize;
fLen = (unsigned int32) total;
Secs2Date( vpb.ioVCrDate, &creDate );
Secs2Date( vpb.ioVLsMod, &modDate );
GetFileAttrString( (HFileInfo *) &vpb, flags );
strcpy( type, "Volm" );
strcpy( crea, "Volm" );
}
else
{
pb.hFileInfo.ioCompletion = NULL;
pb.hFileInfo.ioNamePtr = (StringPtr) str;
pb.hFileInfo.ioVRefNum = vRefNum;
pb.hFileInfo.ioDirID = dirID;
pb.hFileInfo.ioFDirIndex = 0;
err = PBHGetFInfo( &pb, FALSE );
fLen = pb.hFileInfo.ioFlLgLen + pb.hFileInfo.ioFlRLgLen;
GetFileAttrString( (HFileInfo *) &pb, flags );
Secs2Date( pb.hFileInfo.ioFlCrDat, &creDate );
Secs2Date( pb.hFileInfo.ioFlMdDat, &modDate );
TypeToStr( pb.hFileInfo.ioFlFndrInfo.fdType, type );
TypeToStr( pb.hFileInfo.ioFlFndrInfo.fdCreator, crea );
}
if( dirSpec )
sprintf( str, ":%s", last );
else if( what == pathIsFile )
sprintf( str, "%s:%s", path, last );
else
strcpy( str, path );
MacToPath( str );
if( lslmode || lsmmode )
{
int16 len = strlen( str );
Boolean kf = FALSE;
if( fLen > 32000L )
{
fLen /= 1024L;
len = (int16) fLen;
scale = 'K';
if( fLen > 32000L )
{
fLen /= 1024L;
len = (int16) fLen;
scale = 'M';
}
}
else
len = (int16) fLen;
if( lsmmode )
{
if( lsdmode && (what == pathIsDir) || !lsdmode )
procPrintf( ShellWh, ProcID, "%8s %4s %4s %5d%c %s\n",
flags, type, crea, len, scale, str );
}
else
{
if( len > 21 )
{
str[ 21 ] = '\0';
str[ 20 ] = '╔';
}
sprintf( modified, "%02.0d/%02.0d/%2.0d %02.0d:%02.0d %s" ,modDate.month,
modDate.day,modDate.year-1900, modDate.hour % 12, modDate.minute,
( modDate.hour < 12 ? "AM" : "PM") );
if( creDate.year > 2000 )
creDate.year -= 100;
sprintf( created, "%02.0d/%02.0d/%2.0d %02.0d:%02.0d %s" ,creDate.month,
creDate.day, creDate.year-1900, creDate.hour % 12, creDate.minute,
( creDate.hour < 12 ? "AM" : "PM") );
if( lsdmode && (what == pathIsDir) || !lsdmode )
procPrintf( ShellWh, ProcID, "%-22s%4s %4s %5d%c %8s %17s %17s\n",
str, type, crea, len, scale, flags, modified, created );
}
}
else /* plain mode */
if( lsdmode && (what == pathIsDir) || !lsdmode )
procPrintf( ShellWh, ProcID, "%s%c\n", str,
((what == pathIsDir) ? dirChar : ' ') );
}
/*******************************************************************/
void ListNames( WHandle ShellWh, int16 ProcID, char *argument )
{
ShellWindRec **MyShell;
char buf[ 256 ];
pathType pt;
MyShell = (ShellWindRec **) (**ShellWh).thing;
lsHead = TRUE;
/*
* if the argument is a directory then we must list it
*/
strcpy( buf, argument );
if( strcmp( argument, "//" ) == 0 )
strcat( buf, "*" );
pt = SetCurrPath( buf );
/* strcpy( buf, argument );
*/
if( (pt == pathIsDir) || (pt == pathIsVol) )
{
char *cp;
dirSpec = TRUE;
cp = buf;
while( *cp ) cp++;
cp--;
if( ShellPrefs.useMacOSPath )
{
/*
if( (pt == pathIsDir) && (*buf != ':' ) )
{
strcpy( buf, ":" );
strcat( buf, argument );
cp = buf;
while( *cp ) cp++;
cp--;
}
*/
if( *cp == '*' )
;
else if( *cp == ':' )
strcat( buf, "*" );
else
strcat( buf, ":*" );
}
else if( ShellPrefs.useUNIXPath )
{
if( *cp == '*' )
;
else if( *cp == '/' )
strcat( buf, "*" );
else
strcat( buf, "/*" );
}
else if( ShellPrefs.useDOSPath )
{
if( *cp == '*' )
;
else if( *cp == '\\' )
strcat( buf, "*" );
else
strcat( buf, "\\*" );
}
}
else
dirSpec = FALSE;
ResetShellPWD( ShellWh );
if( lsamode )
{
}
ExpandPath( ShellWh, ProcID, buf,(ProcPtr) ListCallBack,
(**MyShell).pwdVRefNum, (**MyShell).pwdDirID );
}
/*******************************************************************/
Boolean DoLS( int16 ProcToken, WHandle ShellWh, int16 ProcID, char *string )
{
char *cp, argument[ 256 ];
int16 i, err, argc;
OsType t;
ShellWindRec **MyShell;
MyShell = (ShellWindRec **) (**ShellWh).thing;
switch( ProcToken )
{
case PROC_INIT :
(**MyShell).Proc[ ProcID ].flags = TRUE;
break;
case PROC_TERM :
case PROC_BREAK :
/* Tell the shell that we're done */
SendOutToken( ShellWh, ProcID, PROC_BREAK );
/* Turn ourself off */
(**MyShell).Proc[ ProcID ].ProcActive = FALSE;
break;
case PROC_STDIN :
if( (**MyShell).Proc[ ProcID ].flags )
{
Boolean hadDirs = FALSE;
(**MyShell).Proc[ ProcID ].flags = FALSE;
lslmode = FALSE;
lsdmode = FALSE;
lsamode = FALSE;
lsmmode = FALSE;
ScanInit();
argc = (**MyShell).Proc[ ProcID ].argc;
/* get arguments */
for( i = 1; i < argc; i++ )
{
GetArgv( ShellWh, ProcID, i, argument );
cp = argument;
if( *cp++ == '-' )
{
while( *cp )
switch( *cp++ )
{
case 'l' : /* Mac long format */
lsmmode = TRUE;
break;
case 'm' : /* long listing */
lslmode = TRUE;
break;
case 'd' : /* list only directories */
lsdmode = TRUE;
break;
case '1' : /* one per line */
break;
case 'a' : /* all entries incl, those that start with . */
lsamode = TRUE;
break;
case 't' : /* Type */
i++;
if( i < argc )
{
char temp[ 256 ];
GetArgv( ShellWh, ProcID, i, temp );
t = StrToType( temp );
ScanForTYPE( t );
}
break;
case 'c' : /* Creator */
i++;
if( i < argc )
{
char temp[ 256 ];
GetArgv( ShellWh, ProcID, i, temp );
t = StrToType( temp );
ScanForCREA( t );
}
break;
}
}
}
/* do list dirs */
for( i = 1; i < (**MyShell).Proc[ ProcID ].argc; i++ )
{
GetArgv( ShellWh, ProcID, i, argument );
if( *argument != '-' )
{
hadDirs = TRUE;
ListNames( ShellWh, ProcID, argument );
}
else /* look for type and creator fields */
{
cp = argument;
cp++;
if( *cp == 't' || *cp == 'c' )
i++;
}
}
if( hadDirs == FALSE )
{
if( ShellPrefs.useMacOSPath )
ListNames( ShellWh, ProcID, ":*" );
else if( ShellPrefs.useUNIXPath )
ListNames( ShellWh, ProcID, "*" );
else if( ShellPrefs.useDOSPath )
ListNames( ShellWh, ProcID, "*" );
}
ScanInit();
/* Tell the shell that we're done */
SendOutToken( ShellWh, ProcID, PROC_BREAK );
/* Turn ourself off */
(**MyShell).Proc[ ProcID ].ProcActive = FALSE;
return( FALSE );
}
}
}